package com.tedu.demo1;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * 使用Spring容器来管理项目中要使用的所有的类
 */
public class Demo {
    static String name;
    static void dosome(){
        System.out.println("=======================");
    }

    public static void main(String[] args) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException, InstantiationException, ClassNotFoundException {
        User user = new User();
        user.sayHello();

        Class cls = Class.forName("com.tedu.demo1.User");
        Object obj = cls.newInstance();
        Method method = cls.getMethod("sayHello");
        method.invoke(obj);

        AnnotationConfigApplicationContext context =
                new AnnotationConfigApplicationContext("com.tedu.demo1");
        User user2 = context.getBean(User.class);
        user2.sayHello();


        Demo.name="name";//静态变量通过类/对象访问
        //name = "";
        Demo demo =new Demo();
        demo.name="name";
        Demo.dosome();//静态方法通过类/对象访问
        //dosome();
        demo.dosome();
    }
}
